package com.blue.controller.workflow;

import com.blue.vo.workflow.BusinessFieldVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.github.yulichang.query.MPJQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blue.common.utils.QueryWrapperUtils;
import org.springframework.web.bind.annotation.*;
import com.blue.common.utils.ConvertUtils;
import com.blue.po.workflow.BusinessFieldPO;
import com.blue.dto.workflow.BusinessFieldDTO;
import com.blue.service.workflow.IBusinessFieldService;
import com.blue.common.entity.ResponseResult;

import java.util.List;


/**
 * 流程业务字段表
 *
 * @author nanjie.chen
 * @email 15696471158@163.com
 * @date 2025-03-10
 */
@RestController
@RequestMapping("/workflow/businessField")
@Tag(name = "流程业务字段表")
public class BusinessFieldController {
    @Autowired
    private IBusinessFieldService businessFieldService;

    @GetMapping("/pageList")
    @Operation(summary = "列表查询")
    public ResponseResult<?> list(BusinessFieldDTO requestDTO,
                                  @RequestParam(value = "pageSize", defaultValue = "10") long pageSize,
                                  @RequestParam(value = "pageNum", defaultValue = "1") long pageNum) {
        BusinessFieldPO businessFieldPO = ConvertUtils.convert(BusinessFieldPO.class, requestDTO);
        MPJQueryWrapper<BusinessFieldPO> queryWrapper = QueryWrapperUtils.initQueryWrapper(businessFieldPO);
        Page<BusinessFieldPO> page = new Page<>(pageNum, pageSize);
        Page<BusinessFieldPO> pageResult = businessFieldService.page(page, queryWrapper);
        return ResponseResult.okResult(pageResult);
    }

    @PostMapping("/getFields")
    @Operation(summary = "获取业务数据字段")
    public ResponseResult<?> getFields(@RequestBody BusinessFieldDTO requestDTO) {
        List<BusinessFieldVO> businessFieldVOS = businessFieldService.getFields(requestDTO.getDefinitionId());
        return ResponseResult.okResult(businessFieldVOS);
    }
}
